Skip to content

Commit 3642a4e

Browse files
authored
Merge pull request #1761 from jlahtinen/remove_native_exception
Stop using NativeException
2 parents 1d46bea + b297328 commit 3642a4e

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,9 @@ def autocommit=(value)
209209
def ping
210210
exec_no_retry("select 1 from dual")
211211
@active = true
212-
rescue NativeException => e
212+
rescue Java::JavaSql::SQLException => e
213213
@active = false
214-
if e.message =~ /^java\.sql\.SQL(Recoverable)?Exception/
215-
raise OracleEnhanced::ConnectionException, e.message
216-
else
217-
raise
218-
end
214+
raise OracleEnhanced::ConnectionException, e.message
219215
end
220216

221217
# Resets connection, by logging off and creating a new connection.
@@ -224,13 +220,9 @@ def reset!
224220
begin
225221
new_connection(@config)
226222
@active = true
227-
rescue NativeException => e
223+
rescue Java::JavaSql::SQLException => e
228224
@active = false
229-
if e.message =~ /^java\.sql\.SQL(Recoverable)?Exception/
230-
raise OracleEnhanced::ConnectionException, e.message
231-
else
232-
raise
233-
end
225+
raise OracleEnhanced::ConnectionException, e.message
234226
end
235227
end
236228

@@ -239,8 +231,8 @@ def with_retry(&block)
239231
should_retry = auto_retry? && autocommit?
240232
begin
241233
yield if block_given?
242-
rescue NativeException => e
243-
raise unless e.message =~ /^java\.sql\.SQL(Recoverable)?Exception: (Closed Connection|Io exception:|No more data to read from socket|IO Error:)/
234+
rescue Java::JavaSql::SQLException => e
235+
raise unless e.message =~ /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/
244236
@active = false
245237
raise unless should_retry
246238
should_retry = false
@@ -455,11 +447,9 @@ def describe(name)
455447
super
456448
end
457449

458-
# Return NativeException / java.sql.SQLException error code
450+
# Return java.sql.SQLException error code
459451
def error_code(exception)
460452
case exception
461-
when NativeException
462-
exception.cause.getErrorCode
463453
when Java::JavaSql::SQLException
464454
exception.getErrorCode
465455
else

spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def kill_current_session
381381
ActiveRecord::Base.connection.auto_retry = false
382382
kill_current_session
383383
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
384-
expect { @conn.exec("SELECT * FROM dual") }.to raise_error(NativeException)
384+
expect { @conn.exec("SELECT * FROM dual") }.to raise_error(Java::JavaSql::SQLRecoverableException)
385385
else
386386
expect { @conn.exec("SELECT * FROM dual") }.to raise_error(OCIError)
387387
end
@@ -399,7 +399,7 @@ def kill_current_session
399399
ActiveRecord::Base.connection.auto_retry = false
400400
kill_current_session
401401
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
402-
expect { @conn.select("SELECT * FROM dual") }.to raise_error(NativeException)
402+
expect { @conn.select("SELECT * FROM dual") }.to raise_error(Java::JavaSql::SQLRecoverableException)
403403
else
404404
expect { @conn.select("SELECT * FROM dual") }.to raise_error(OCIError)
405405
end

0 commit comments

Comments
 (0)