rsim / oracle-enhanced

Oracle enhaced adapter for ActiveRecord
MIT License
544 stars 308 forks source link

Enhance workaround for WeakMap with jruby >= 9.4.6.0 #2360

Open iaddict opened 4 months ago

iaddict commented 4 months ago

Since jruby 9.4.6.0 the missing methods on ObjectSpace::WeakMap have been implemented.

See: https://github.com/jruby/jruby/pull/6683

Without this fix the gem does not work on jruby 9.4.6.0.

laumacirule commented 4 months ago

While pending on a new version, for the activerecord-oracle_enhanced-adapter 6.1.6 that we are currently using, we implemented a temporary workaround to rescue the NameError in lib/active_record/connection_adapters/oracle_enhanced_adapter.rb

begin
  load File.expand_path("active_record/connection_adapters/oracle_enhanced_adapter.rb", $:.grep(/oracle_enhanced/).first)
rescue NameError => e
  raise e unless e.message =~ /undefined field 'map'/
end
rammpeter commented 2 weeks ago

Another workaround to patch the gem each time after fresh install like in CI pipelines: add this snippet as last step in RAILS_ROOT/config/boot.rb

# Workaround to avoid the error: undefined field 'map' for class 'Java::OrgJruby::RubyObjectSpace::WeakMap'
# with oracle-enhanced-adapter 6.1.6 and JRuby 9.4.6.0 and following versions
# Prevent execution of the code block in the if statement by comparing RUBY_ENGINE with a not existing value
# This patches the gem each time it is installed again
# Peter Ramm, 2024-06-18

gem_path = Gem::Specification.find_by_name('activerecord-oracle_enhanced-adapter').gem_dir
file_path = File.join(gem_path, 'lib', 'active_record', 'connection_adapters', 'oracle_enhanced_adapter.rb')
content = File.read(file_path)
new_content = content.gsub("if RUBY_ENGINE == \"jruby\"", "if RUBY_ENGINE == \"xjruby\"")
File.open(file_path, 'w') { |file| file.write(new_content) }