I've been using Jruby with ActiveRecord-JDBC for a couple of months,
mostly for read-only, not worrying about migrations. Fairly simple, I'm
using the open source JT400 JDBC driver. I also modified the
ActiveRecord-JDBC by:
1. Copied the existing jdbc_db2 adapter.rb in the lib/jdbc_adapter as
jdbc_as400.rb
a. Modified the offset code:
# original didn't sort using :order condition passed into the sql.
# Must insert the order condition into the over() like: over(ORDER
BY order_date DESC)
# Take the options[:order] and strip out the table names
("MCLIBD.INP400" --> "INP400")
# Use over() if options[:order] doesn't exist. Will use default
ordering of table.
def add_limit_offset!(sql, options)
if limit = options[:limit]
offset = options[:offset] || 0
order_by = ""
order_by = "ORDER BY " << options[:order].gsub(/\b\w+\.\b/," ")
if options[:order]
sql.gsub!(/SELECT/i, "SELECT B.* FROM (SELECT A.*, row_number()
over (#{order_by}) AS internal$rownum FROM (SELECT")
sql << ") A ) B WHERE B.internal$rownum > #{offset} AND
B.internal$rownum <= #{limit + offset}"
end
end
2. Modified the lib/active_record/connection_adapters/jdbc_adapter to
include the as400 adapter as an option.
class JdbcColumn < Column
COLUMN_TYPES = {
/oracle/i => lambda {|cfg,col|
col.extend(JdbcSpec::Oracle::Column)},
/mysql/i => lambda {|cfg,col|
col.extend(JdbcSpec::MySQL::Column)},
/postgre/i => lambda {|cfg,col|
col.extend(JdbcSpec::PostgreSQL::Column)},
/sqlserver|tds/i => lambda {|cfg,col|
col.extend(JdbcSpec::MsSQL::Column)},
/hsqldb|\.h2\./i => lambda {|cfg,col|
col.extend(JdbcSpec::HSQLDB::Column)},
/derby/i => lambda {|cfg,col|
col.extend(JdbcSpec::Derby::Column)},
/as400/i => lambda {|cfg,col|
col.extend(JdbcSpec::AS400::Column)},
/db2/i => lambda {|cfg,col|
And
class JdbcAdapter < AbstractAdapter
ADAPTER_TYPES = {
/oracle/i => lambda{|cfg,adapt| adapt.extend(JdbcSpec::Oracle)},
/mimer/i => lambda{|cfg,adapt| adapt.extend(JdbcSpec::Mimer)},
/postgre/i => lambda{|cfg,adapt|
adapt.extend(JdbcSpec::PostgreSQL)},
/mysql/i => lambda{|cfg,adapt| adapt.extend(JdbcSpec::MySQL)},
/sqlserver|tds/i => lambda{|cfg,adapt|
adapt.extend(JdbcSpec::MsSQL)},
/hsqldb|\.h2\./i => lambda{|cfg,adapt|
adapt.extend(JdbcSpec::HSQLDB)},
/derby/i => lambda{|cfg,adapt| adapt.extend(JdbcSpec::Derby)},
/as400/i => lambda{|cfg,adapt| adapt.extend(JdbcSpec::AS400)},
/db2/i => lambda{|cfg,adapt|
I'm currently using ActiveRecord-JDBC-0.3.1. Had trouble using 0.4.0
with Tomcat.
Note that journaling must be turned on for the iSeries (AS/400) tables!
I did some initial experiments with CRUD that seemed to work, but almost
all of the experience is with reading data and image BLOBs from the
tables. I'm also not too worried about migrations, since I can't make
those changes in production code anyway.
Donald Parish
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel