Skip to content

Instantly share code, notes, and snippets.

@boskowski
Last active December 7, 2015 15:51
Show Gist options
  • Save boskowski/92d6803e2c152e1fdece to your computer and use it in GitHub Desktop.
Save boskowski/92d6803e2c152e1fdece to your computer and use it in GitHub Desktop.
ActiveRecord vs. barebones connection
$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build pap6480-20150129_02)
IBM J9 VM (build 2.8, JRE 1.8.0 OS/400 ppc64-64 Compressed References 20150116_231420 (JIT enabled, AOT enabled)
J9VM - R28_Java8_GA_20150116_2030_B231420
JIT - tr.r14.java_20150109_82886.02
GC - R28_Java8_GA_20150116_2030_B231420_CMPRSS
J9CL - 20150116_231420)
JCL - 20150123_01 based on Oracle jdk8u31-b12
$ jruby -v
jruby 1.7.23 (1.9.3p551) 2015-11-24 f496dd5 on IBM J9 VM 2.8 +jit [OS/400-ppc64]
$ bin/rails c
io/console not supported; tty will not be manipulated
Loading development environment (Rails 4.2.5)
irb(main):001:0> ActiveRecord::Base.establish_connection(adapter: 'as400', native: true)
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x38295b45 @spec=#<ActiveRecord::ConnectionAdapters::ConnectionSpecification:0x37f500cd @config={:adapter=>"as400", :native=>true}, @adapter_method="as400_connection">, @connections=[], @checkout_timeout=5, @automatic_reconnect=true, @available=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Queue:0x5c156b85 @lock=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x38295b45 ...>, @queue=[], @cond=#<MonitorMixin::ConditionVariable:0x7a79cff4 @monitor=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x38295b45 ...>, @cond=#<ConditionVariable:0x71b24374>>, @num_waiting=0>, @size=5, @reaper=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper:0x4c6ee49c @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x38295b45 ...>, @frequency=nil>, @reserved_connections=#<ThreadSafe::Cache:0xa4318b2c @default_proc=nil>, @mon_mutex=#<Mutex:0xc4adfbb3>, @mon_owner=nil, @mon_count=0>
irb(main):002:0> pool.connection
=> #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x142e521d @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x6ec08b41 @spec=#<ActiveRecord::ConnectionAdapters::ConnectionSpecification:0xd2f326cd @config={:adapter=>"as400", :native=>true, :transaction_isolation=>"none", :url=>"jdbc:db2:*local;transaction isolation=none", :driver=>"com.ibm.as400.access.AS400JDBCDriver", :adapter_spec=>ArJdbc::AS400, :connection_alive_sql=>"SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY"}, @adapter_method="as400_connection">, @connections=[#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x142e521d ...>], @checkout_timeout=5, @automatic_reconnect=true, @available=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Queue:0x2c69a339 @lock=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x6ec08b41 ...>, @queue=[], @cond=#<MonitorMixin::ConditionVariable:0x34051f5c @monitor=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x6ec08b41 ...>, @cond=#<ConditionVariable:0xc47c887c>>, @num_waiting=0>, @size=5, @reaper=#<ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper:0x12c2564d @pool=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x6ec08b41 ...>, @frequency=nil>, @reserved_connections=#<ThreadSafe::Cache:0x9e3913ae @default_proc=nil>, @mon_mutex=#<Mutex:0x3a09d0fc>, @mon_owner=nil, @mon_count=0>, @query_cache={}, @schema_cache=#<ActiveRecord::ConnectionAdapters::SchemaCache:0x8cfaa9b2 @primary_keys={}, @columns={}, @tables={}, @columns_hash={}, @connection=#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x142e521d ...>>, @config={:adapter=>"as400", :native=>true, :transaction_isolation=>"none", :url=>"jdbc:db2:*local;transaction isolation=none", :driver=>"com.ibm.as400.access.AS400JDBCDriver", :adapter_spec=>ArJdbc::AS400, :connection_alive_sql=>"SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY", :retry_count=>1, :driver_instance=>#<ActiveRecord::ConnectionAdapters::JdbcDriver:0xfa812171 @properties={}, @name="com.ibm.as400.access.AS400JDBCDriver", @driver=#<Java::ComIbmAs400Access::AS400JDBCDriver:0x1dcf66fa>, @driver_class=Java::ComIbmAs400Access::AS400JDBCDriver>}, @mon_mutex=#<Mutex:0x25b37bcb>, @mon_count=0, @connection=#<ActiveRecord::ConnectionAdapters::DB2JdbcConnection:0xbb41a0ff @adapter=#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x142e521d ...>, @config={:adapter=>"as400", :native=>true, :transaction_isolation=>"none", :url=>"jdbc:db2:*local;transaction isolation=none", :driver=>"com.ibm.as400.access.AS400JDBCDriver", :adapter_spec=>ArJdbc::AS400, :connection_alive_sql=>"SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY", :retry_count=>1, :driver_instance=>#<ActiveRecord::ConnectionAdapters::JdbcDriver:0xfa812171 @properties={}, @name="com.ibm.as400.access.AS400JDBCDriver", @driver=#<Java::ComIbmAs400Access::AS400JDBCDriver:0x1dcf66fa>, @driver_class=Java::ComIbmAs400Access::AS400JDBCDriver>}, @jndi=false, @connection=nil>, @prepared_statements=false, @instrumenter=#<ActiveSupport::Notifications::Instrumenter:0xcab5772b @notifier=#<ActiveSupport::Notifications::Fanout:0x92d4a1ea @subscribers=[#<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0xe1814bcf @pattern="render_bind.active_record", @delegate=#<ActiveRecord::LogSubscriber:0xeabd3b48 @odd=false, @queue_key="ActiveRecord::LogSubscriber-4080", @patterns=["render_bind.active_record", "odd?.active_record", "sql.active_record", "logger.active_record"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0xcaa1cb1c @pattern="odd?.active_record", @delegate=#<ActiveRecord::LogSubscriber:0xeabd3b48 @odd=false, @queue_key="ActiveRecord::LogSubscriber-4080", @patterns=["render_bind.active_record", "odd?.active_record", "sql.active_record", "logger.active_record"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x481cc10a @pattern="sql.active_record", @delegate=#<ActiveRecord::LogSubscriber:0xeabd3b48 @odd=false, @queue_key="ActiveRecord::LogSubscriber-4080", @patterns=["render_bind.active_record", "odd?.active_record", "sql.active_record", "logger.active_record"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x24406e34 @pattern="logger.active_record", @delegate=#<ActiveRecord::LogSubscriber:0xeabd3b48 @odd=false, @queue_key="ActiveRecord::LogSubscriber-4080", @patterns=["render_bind.active_record", "odd?.active_record", "sql.active_record", "logger.active_record"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x56c86094 @pattern="sql.active_record", @delegate=#<ActiveRecord::ExplainSubscriber:0xf1d4322d>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x8638de5f @pattern="deliver.action_mailer", @delegate=#<ActionMailer::LogSubscriber:0xbdec7632 @queue_key="ActionMailer::LogSubscriber-4092", @patterns=["deliver.action_mailer", "receive.action_mailer", "process.action_mailer", "logger.action_mailer"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0xc8c9f5ab @pattern="receive.action_mailer", @delegate=#<ActionMailer::LogSubscriber:0xbdec7632 @queue_key="ActionMailer::LogSubscriber-4092", @patterns=["deliver.action_mailer", "receive.action_mailer", "process.action_mailer", "logger.action_mailer"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0xce08107c @pattern="process.action_mailer", @delegate=#<ActionMailer::LogSubscriber:0xbdec7632 @queue_key="ActionMailer::LogSubscriber-4092", @patterns=["deliver.action_mailer", "receive.action_mailer", "process.action_mailer", "logger.action_mailer"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x2880128e @pattern="logger.action_mailer", @delegate=#<ActionMailer::LogSubscriber:0xbdec7632 @queue_key="ActionMailer::LogSubscriber-4092", @patterns=["deliver.action_mailer", "receive.action_mailer", "process.action_mailer", "logger.action_mailer"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x780dc53 @pattern="render_template.action_view", @delegate=#<ActionView::LogSubscriber:0x4850b9c5 @root=nil, @queue_key="ActionView::LogSubscriber-4094", @patterns=["render_template.action_view", "render_partial.action_view", "logger.action_view", "render_collection.action_view"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x3eb838ea @pattern="render_partial.action_view", @delegate=#<ActionView::LogSubscriber:0x4850b9c5 @root=nil, @queue_key="ActionView::LogSubscriber-4094", @patterns=["render_template.action_view", "render_partial.action_view", "logger.action_view", "render_collection.action_view"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0xfc8314e6 @pattern="logger.action_view", @delegate=#<ActionView::LogSubscriber:0x4850b9c5 @root=nil, @queue_key="ActionView::LogSubscriber-4094", @patterns=["render_template.action_view", "render_partial.action_view", "logger.action_view", "render_collection.action_view"]>, @can_publish=false>, #<ActiveSupport::Notifications::Fanout::Subscribers::Evented:0x522d9a9b @pattern="render_collection.action_view", @delegate=#<ActionView::LogSubscriber:0x4850b9c5 @root=nil, @queue_key="ActionView::LogSubscriber-4094", @patterns=["render_template.action_view", "render_partial.action_view", "logger.action_view", "render_collection.action_view"]>, @can_publish=false>], @listeners_for=#<ThreadSafe::Cache:0xa39bd25f @default_proc=nil>, @_mutex=#<Mutex:0xe863e310>>, @id="c743e7b7bd06bcfbf695">, @visitor=#<#<Class:0x91ab2ace>:0xdd868fe @block=nil, @dispatch={}, @connection=#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x142e521d ...>>, @logger=#<ActiveSupport::Logger:0xa2fc845b @default_formatter=#<Logger::Formatter:0x18632d96 @datetime_format=nil>, @progname=nil, @level=0, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x6add5522 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0xa4134ad1 @shift_age=nil, @mutex=#<Logger::LogDevice::LogDeviceMutex:0xe38a4da6 @mon_mutex=#<Mutex:0x47e6dc8a>, @mon_owner=nil, @mon_count=0>, @dev=#<File:/home/yann/iseries/log/development.log>, @shift_size=nil, @filename=nil>>, @transaction_manager=#<ActiveRecord::ConnectionAdapters::TransactionManager:0xd131f9ed @stack=[], @connection=#<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x142e521d ...>>, @query_cache_enabled=false, @owner=#<Thread:0x1650812a run>, @mon_owner=nil>
irb(main):003:0> pool.connected?
=> true
irb(main):004:0> pool.connection.execute("SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY")
(4.0ms) SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY
ActiveRecord::StatementInvalid: ActiveRecord::ConnectionNotEstablished: no connection available: SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY
from arjdbc/jdbc/RubyJdbcConnection.java:587:in `execute'
from /home/yann/jruby/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.19/lib/arjdbc/jdbc/adapter.rb:595:in `_execute'
from /home/yann/jruby/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.19/lib/arjdbc/jdbc/adapter.rb:571:in `execute'
from /home/yann/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `log'
from /home/yann/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /home/yann/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
from /home/yann/jruby/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.19/lib/arjdbc/jdbc/adapter.rb:571:in `execute'
from (irb):7:in `evaluate'
from org/jruby/RubyKernel.java:1079:in `eval'
from org/jruby/RubyKernel.java:1479:in `loop'
from org/jruby/RubyKernel.java:1242:in `catch'
from org/jruby/RubyKernel.java:1242:in `catch'
from /home/yann/jruby/lib/ruby/gems/shared/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
from /home/yann/jruby/lib/ruby/gems/shared/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
from /home/yann/jruby/lib/ruby/gems/shared/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/yann/jruby/lib/ruby/gems/shared/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/yann/jruby/lib/ruby/gems/shared/gems/railties-4.2.5/lib/rails/commands.rb:17:in `(root)'
from org/jruby/RubyKernel.java:1040:in `require'
irb(main):005:0> conn = java.sql.DriverManager.getConnection("jdbc:db2:*local"); stat = conn.createStatement;
rb(main):006:0* rs = stat.executeQuery("SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY"); rs.next; rs.getInt(1)
=> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment