Skip to content

Commit 46054fe

Browse files
yahondaclaude
andcommitted
Namespace ORACLE_DRIVER under PLSQL::JDBCConnection
Move the ORACLE_DRIVER constant and the DriverManager.registerDriver call inside class PLSQL::JDBCConnection so the driver instance is no longer defined as a top-level Ruby constant. This avoids polluting the global namespace of the host application. Update spec_helper.rb to reference the constant via its fully qualified name PLSQL::JDBCConnection::ORACLE_DRIVER. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f129738 commit 46054fe

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/plsql/jdbc_connection.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,25 @@
3535
end
3636
end
3737

38-
ORACLE_DRIVER = Java::oracle.jdbc.OracleDriver.new
39-
java.sql.DriverManager.registerDriver ORACLE_DRIVER
40-
4138
# set tns_admin property from TNS_ADMIN environment variable
4239
if !java.lang.System.get_property("oracle.net.tns_admin") && ENV["TNS_ADMIN"]
4340
java.lang.System.set_property("oracle.net.tns_admin", ENV["TNS_ADMIN"])
4441
end
4542

46-
rescue LoadError, NameError
43+
rescue LoadError
4744
# JDBC driver is unavailable.
4845
raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. Please install #{ojdbc_jars.empty? ? "Oracle JDBC" : ojdbc_jars.join(' or ') } library."
4946
end
5047

5148
module PLSQL
5249
class JDBCConnection < Connection # :nodoc:
50+
begin
51+
ORACLE_DRIVER = Java::oracle.jdbc.OracleDriver.new
52+
java.sql.DriverManager.registerDriver ORACLE_DRIVER
53+
rescue NameError
54+
raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver."
55+
end
56+
5357
def self.create_raw(params)
5458
url = jdbc_connection_url(params)
5559
conn = begin

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get_connection(user_number = 0)
9595
# bypass DriverManager to work in cases where ojdbc*.jar
9696
# is added to the load path at runtime and not on the
9797
# system classpath
98-
ORACLE_DRIVER.connect(get_connection_url, java.util.Properties.new.tap do |props|
98+
PLSQL::JDBCConnection::ORACLE_DRIVER.connect(get_connection_url, java.util.Properties.new.tap do |props|
9999
props.setProperty("user", database_user)
100100
props.setProperty("password", database_password)
101101
end)

0 commit comments

Comments
 (0)