简体   繁体   English

如何使用带有 DB2/400 数据库的 JRuby 上的 DataMapper 在 Rails 3.1 上使用 Ruby?

[英]How do I use Ruby on Rails 3.1 with DataMapper on JRuby with a DB2/400 database?

I am developing a Rails 3.1 application on top of a legacy DB2/400 database.我正在遗留 DB2/400 数据库之上开发Rails 3.1应用程序。 Because of the better support for legacy schemas, I opted to use DataMapper instead of ActiveRecord as the ORM.由于对遗留模式的更好支持,我选择使用DataMapper而不是ActiveRecord作为 ORM。 The application is going to be deployed on JRuby .该应用程序将部署在JRuby上。

What is the best way to access a DB2 database in this case?在这种情况下,访问 DB2 数据库的最佳方式是什么?

My initial research indicated that this would be trivial, since one of the major selling points of using JRuby on Rails is that you get JDBC, and thus access to pretty much any database on the planet.我最初的研究表明这将是微不足道的,因为使用 JRuby on Rails 的主要卖点之一是您可以获得 JDBC,因此可以访问地球上几乎任何数据库。

However, it appears that is not necessarily true, in particular, there doesn't seem to be any driver for either ActiveRecord or DataMapper/DataObjects for using DB2 over JDBC.但是,这似乎不一定正确,特别是,似乎没有任何 ActiveRecord 或 DataMapper/DataObjects 的驱动程序可以在 Z82269B9B71AB4A7732F6958610214 上使用 DB2。

Do I have to write my own driver?我必须编写自己的驱动程序吗? From reading the source code of the various existing DataObjects/DataMapper JDBC drivers , this shouldn't be too hard, but it is something I'd rather like to avoid.通过阅读各种现有 DataObjects/DataMapper JDBC 驱动程序的源代码,这应该不会太难,但这是我宁愿避免的。

Is there any ready-made solution (library, gem, blog post, tutorial) for using DB2/400 with JRuby on Rails with DataMapper?是否有任何现成的解决方案(库、gem、博客文章、教程)用于将 DB2/400 与 JRuby on Rails 与 DataMapper 结合使用? If not, how do I do it?如果没有,我该怎么做?

activerecord-jdbc-adapter has built-in support for DB2. activerecord-jdbc-adapter内置了对 DB2 的支持。 Is there a particular schema problem you have?您有特定的架构问题吗? I've been able to get ActiveRecord to work with several legacy schemas.我已经能够让 ActiveRecord 与几个遗留模式一起工作。

Update :更新

For table names that don't match, simply put对于不匹配的表名,只需输入

set_table_name "my_table_name"

in the model.在 model 中。 You can specify the class used in a relationhip, and/or the foreign key:您可以指定关系中使用的 class 和/或外键:

has_many :somethings, :class_name => 'something_else', :foreign_key => 'something_else_id'

(For more of the options see http://apidock.com/rails/ActiveRecord/Associations/ClassMethods ). (有关更多选项,请参阅http://apidock.com/rails/ActiveRecord/Associations/ClassMethods )。

For composite primary keys, see the Composite Primary Keys gem.对于复合主键,请参阅复合主键gem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM