JRuby 1.6.7、ActiveRecord 3.2.3、activerecord-jdbc-adapter 1.2.2、activerecord-jdbcsqlanywhere-adapter-1.1.1、および現在のSybaseJDBC4ドライバーを使用しています。現時点では、完全なRubyOnRailsアプリケーションを使用することはできません。単体テストを実行すると、次のエラーが発生します。
NoMethodError:未定義のメソッド `find_by_configuration_name'for# method_missing at org / jruby / RubyBasicObject.java:1687 method_missing at /home/lynchcs/.rvm/gems/jruby-1.6.5.1/gems/activerecord-3.2.3/lib/active_record/dynamic_matchers.rb:27
テーブルを正しく識別する単体テストでスキーマダンプを実行できます。これがテーブルのスキーマです。
create_table "THE_CONFIGURATION", :primary_key => "CONFIGURATION_ID", :force => true do |t|
t.string "CONFIGURATION_GROUP", :limit => 32
t.string "CONFIGURATION_TYPE", :limit => 32
t.string "CONFIGURATION_NAME", :limit => 32
t.string "CONFIGURATION_TEXT", :limit => 7168
end
これが私がそのために作ったモデルです。
require 'rubygems'
require 'active_record'
class Configuration < ActiveRecord::Base
self.table_name = 'SOART_CONFIGURATION'
self.primary_key = 'configuration_id'
end
これが、接続を管理するために使用したクラスです。このクラスはデータベースに正常に接続し、クエリを実行します。
require 'java'
require 'rubygems'
require 'active_record'
class ConnectionMaster
def test_object
"ARBITRARY"
end
def set_connection
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc' ,
:driver => 'com.sybase.jdbc4.jdbc.SybDriver' ,
:url => 'jdbc:sybase:Tds:192.168.137.137:1111/MYAPP' ,
:username => 'noneya' ,
:password => 'noneya'
)
ActiveRecord::Base.connection.execute("SELECT 'ARBITRARY' AS ARBITRARY")
end
def clear_connections
ActiveRecord::Base.clear_active_connections!
end
end
「config=Configuration.find_by_configuration_name('test')」を実行するとエラーになります。この行をコメントアウトすると、「config.configuration_text」行でエラーになります。
public void testRubyDatabaseQuery() {
String theValue = "test";
String jrubyCode =
"require 'connection_master' \n"
+ "require 'configuration' \n"
+ "cm = ConnectionMaster.new \n"
+ "cm.set_connection \n"
+ "puts 'black cow of revenge' \n"
+ "config = Configuration.find(:all,:conditions => ['configuration_name=?','test']) \n"
+ "config = Configuration.find_by_configuration_name('test') \n"
+ "puts 'red cow of revenge' \n"
+ "cm.clear_connections \n"
+ "config.configuration_text \n";
String executeValue = (String)JRubyMaster.execute(jrubyCode);
this.assertEquals("executeValue and theValue do not match.", theValue, executeValue);
}