Nick Sieger: Tag activerecord http://blog.nicksieger.com/articles/tag/activerecord?tag=activerecord en-us 40 activerecord-jdbc-adapter 1.0.0 <p>Just a quick note that <code>activerecord-jdbc-adapter</code> has finally hit 1&#46;0&#46;0&#46; Install it today:</p> <pre><code>gem install activerecord-jdbc-adapter </code></pre> <p>Included are adapters for <a href="http://www.mysql.com/" title="MySQL :: The world's most popular open source database">MySQL</a>, <a href="http://www.postgresql.org/" title="PostgreSQL: The world's most advanced open source database">PostgreSQL</a>, <a href="http://www.sqlite.org/" title="SQLite Home Page">SQLite3</a>, <a href="http://db.apache.org/derby/" title="Apache Derby">Derby</a>, <a href="http://hsqldb.org/" title="HSQLDB">HSQLDB</a>, <a href="http://www.h2database.com/" title="H2 Database Engine">H2</a>, and <a href="http://www.microsoft.com/sqlserver/2008/en/us/" title="SQL Server 2008 Overview, data platform, store data | Microsoft">Microsoft SQL Server</a>&#46;</p> <pre><code>gem install activerecord-jdbcmysql-adapter gem install activerecord-jdbcpostgresql-adapter gem install activerecord-jdbcsqlite3-adapter gem install activerecord-jdbcderby-adapter gem install activerecord-jdbchsqldb-adapter gem install activerecord-jdbch2-adapter gem install activerecord-jdbcmssql-adapter </code></pre> <p>You can also use <code>activerecord-jdbc-adapter</code> with Oracle, DB2, Sybase, and Informix&#46; Just ensure that the database JDBC driver jar files are mentioned in <code>$CLASSPATH</code> or <code>require</code> them directly in your script or application&#46; Then, configure <code>database.yml</code> with <code>adapter:</code> set to one of <code>oracle</code>, <code>db2</code>, <code>sybase</code>, or <code>informix</code>&#46;</p> <p>This release promises superb compatibility with Rails 3&#46; We now have the ActiveRecord test suite <a href="http://ci.jruby.org/view/Rails">running in CI</a> and the 1&#46;0&#46;0 release is 100% green when run on MySQL&#46; (SQLite3 is right behind with just 13 failures, and we hope to fix those soon&#46;)</p> <p>As <a href="/articles/2010/02/24/jruby-and-rails-3-sitting-in-a-tree">mentioned before</a>, to get started with Rails 3, JRuby and <code>activerecord-jdbc-adapter</code>, simply run:</p> <pre><code>$ rails new app --database mysql --template http://jruby.org ... apply http://jruby.org apply http://jruby.org/templates/default.rb gsub Gemfile gsub config/database.yml $ cd app &amp;&amp; bundle install ... Using activerecord-jdbc-adapter (1.0.0) ... Using jdbc-mysql (5.0.4) ... Using rails (3.0.0) Your bundle is complete! Use `bundle show [gemname]` ... </code></pre> <p>One new feature in 1&#46;0&#46;0 is the ability to define an extension adapter for your proprietary JDBC database without needing to hack the <code>activerecord-jdbc-adapter</code> source code&#46; To get you started we extracted the <code>activerecord-cachedb-adapter</code> and <a href="http://github.com/nicksieger/activerecord-cachedb-adapter">put it on Github</a> for you to use as a template&#46;</p> <p>The 1&#46;0&#46;0 release had over 200 commits poured into it and lots of great help from the community&#46; Thanks to David Kellum, Dmitry Denisov, Dwayne Litzenberger, Gregor Schmidt, James Walker, John Duff, Joshua Suggs, Nicholas J Kreucher, Peter Donald, Geoff Longman, Uwe Kubosch, Youhei Kondou, Michael Pitman, Alex B, and Ryan Bell for their contributions to this release&#46;</p> <p>Enjoy!</p> Thu, 14 Oct 2010 15:25:51 +0000 urn:uuid:8f70150f-ec57-4646-afaa-c3e07b6df7c3 Nick Sieger http://blog.nicksieger.com/articles/2010/10/14/activerecord-jdbc-adapter-1-0-0 jruby jdbc activerecord rails rails3 http://blog.nicksieger.com/articles/trackback/573 ActiveRecord-JDBC 0.6 Released! <p>Just out is ActiveRecord&#45;JDBC 0&#46;6, the post&#45;RubyConf release&#46;</p> <p>The sparkly new feature is Rails 2&#46;0 support&#46; In the soon&#45;to&#45;be&#45;released Rails 2&#46;0 (edge), Rails will automatically look for and load an adapter gem based on the name of the adapter you specify in <code>database.yml</code>&#46; Example:</p> <pre><code>development: adapter: funkdb ... </code></pre> <p>With this database configuration, Rails will attempt to load the <code>activerecord-funkdb-adapter</code> gem, require the <code>active_record/connection_adapters/funkdb_adapter</code> library, and call the method <code>ActiveRecord::Base.funkdb_connection</code> in order to obtain a connection to the database&#46; (This is the mechanism used to off&#45;load non&#45;core adapters out of the Rails codebase&#46;)</p> <p>We can leverage this convention to make it easier than ever to get started using JRuby with your Rails application&#46; So, the first thing new in the 0&#46;6 release is the name&#46; You now install <code>activerecord-jdbc-adapter</code>:</p> <pre><code>jruby -S gem install activerecord-jdbc-adapter </code></pre> <p>But wait, there&#8217;s more! We also have adapters for four open&#45;source databases, including MySQL, PostgreSQL, and two embedded Java databases, Derby and HSQLDB&#46; And, for your convenience, we&#8217;ve bundled the JDBC drivers in dependent gems, so you don&#8217;t have to go hunting them down if you don&#8217;t have them handy&#46;</p> <p>Check this out&#46; Get a <a href="http://dist.codehaus.org/jruby/jruby-bin-1.0.2.zip">fresh copy of JRuby 1&#46;0&#46;2</a>, unpack it, and add the <code>bin</code> directory to your path&#46; Install the adapter:</p> <pre><code>$ jruby -S gem install activerecord-jdbcderby-adapter --include-dependencies Successfully installed activerecord-jdbcderby-adapter-0.6 Successfully installed activerecord-jdbc-adapter-0.6 Successfully installed jdbc-derby-10.2.2.0 </code></pre> <p>In your Rails application, freeze to edge Rails (soon to be Rails 2&#46;0)&#46;</p> <pre><code>rake rails:freeze:edge </code></pre> <p>Re&#45;run the Rails command, regenerating configuration files&#46;</p> <pre><code>jruby ./vendor/rails/railties/bin/rails . </code></pre> <p>Currently, Rails 2&#46;0 uses <code>openssl</code> for the HMAC digest used in the new cookie session store, so we have to install the <code>jruby-openssl</code> gem:</p> <pre><code>jruby -S gem install jruby-openssl </code></pre> <p>Now, update your config/database&#46;yml as follows:</p> <pre><code>development: adapter: jdbcderby database: db/development </code></pre> <p>Re&#45;run your migrations, and you should now see a Derby database footprint in the <code>db/development</code> directory&#46;</p> <pre><code>$ ls -l db/development total 24 -rw-r--r-- 1 nicksieg nicksieg 38 Nov 6 08:24 db.lck -rw-r--r-- 1 nicksieg nicksieg 4 Nov 6 08:24 dbex.lck drwxr-xr-x 5 nicksieg nicksieg 170 Nov 6 08:24 log/ drwxr-xr-x 65 nicksieg nicksieg 2210 Nov 6 08:24 seg0/ -rw-r--r-- 1 nicksieg nicksieg 882 Nov 6 08:24 service.properties drwxr-xr-x 2 nicksieg nicksieg 68 Nov 6 08:24 tmp/ </code></pre> <p>That&#8217;s it! To <strong>re&#45;emphasize, to make your application run under JRuby, no longer will you need to</strong> a) find and download appropriate JDBC drivers, b) wonder where they should be placed so that JRuby will find them, or c) make custom changes to <code>config/environment.rb</code>&#46; All that&#8217;s taken care of you if you use one of the following adapters:</p> <ul> <li><code>activerecord-jdbcmysql-adapter</code> (MySQL)</li> <li><code>activerecord-jdbcpostgresql-adapter</code> (PostgreSQL)</li> <li><code>activerecord-jdbcderby-adapter</code> (Derby)</li> <li><code>activerecord-jdbchsqldb-adapter</code> (HSQLDB)</li> </ul> <p>If you need to connect to a different database, you&#8217;ll still need to place your database&#8217;s JDBC driver jar file in the appropriate place and use the straight <code>activerecord-jdbc-adapter</code>&#46; Also note that in this case, and for Rails 1&#46;2&#46;x in general, you&#8217;ll still need to add that pesky <code>require</code> statement to <code>config/environment.rb</code>&#46;</p> <p>As always, there are bug fixes too (though we haven&#8217;t been tracking exactly which ones are fixed)&#46; We&#8217;re starting to file <a href="http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&amp;&amp;pid=11295&amp;resolution=-1&amp;component=12786&amp;sorter/field=priority&amp;sorter/order=ASC">ActiveRecord&#45;JDBC bugs</a> in the JRuby JIRA now, and will be putting in future AR&#45;JDBC versions to target soon too&#46; So, please <a href="http://jira.codehaus.org/secure/CreateIssue.jspa?pid=11295">file new bugs in JIRA</a> (and select component &#8220;ActiveRecord&#45;JDBC&#8221;) rather than in the antiquated Rubyforge tracker&#46;</p> Tue, 06 Nov 2007 15:00:00 +0000 urn:uuid:5fa03b7c-e168-4bd4-be31-b0237344c159 Nick Sieger http://blog.nicksieger.com/articles/2007/11/06/activerecord-jdbc-0-6-released jruby rails activerecord http://blog.nicksieger.com/articles/trackback/345 Fresh 0.9.2 activerecord-jdbc-adapter Release <p>As <a href="http://markmail.org/message/mkwdu56wp74pj4tf">announced last week on the jruby&#45;user list</a>, 0&#46;9&#46;2, the latest <code>activerecord-jdbc-adapter</code> release, has been pushed out&#46; Please install the gem in the usual fashion and try it out on your applications&#46;</p> <p>One of the <a href="http://jira.codehaus.org/browse/JRUBY-3502">most contentious bugs</a> broke <code>db:create</code> and <code>db:drop</code>, ruining the quick&#45;start workflow that Rails is known for&#46; To fix this, a creative solution was needed that ended up bringing some nice benefits&#46;</p> <p>The problem stemmed from the fact that some database setup tasks in Rails 2&#46;3 no longer load the environment; instead they just load the configuration data and work with that&#46; This means that there is no easy way to hook into Rails and override those tasks, which is <a href="http://github.com/nicksieger/activerecord-jdbc-adapter/blob/master/lib/jdbc_adapter/jdbc.rake">what activerecord&#45;jdbc needs to do</a>&#46;</p> <p>The solution I ended up with was to create a <code>jdbc</code> Rails generator that inserts a couple files into your rails application that inject the JDBC logic into ActiveRecord and the database rake tasks&#46; To wit:</p> <pre><code>$ jruby script/generate jdbc exists config/initializers create config/initializers/jdbc.rb exists lib/tasks create lib/tasks/jdbc.rake </code></pre> <p>The upside of this new technique is that now that we have a way to ensure the JDBC adapter is properly injected into Rails, and you no longer need to use adapter names like <code>jdbcmysql</code>, <code>jdbcsqlite3</code> and the like&#46; The net result is that <strong>database&#46;yml no longer needs to be modified</strong> for the default Rails databases (<code>mysql</code>, <code>sqlite3</code>, <code>postgresql</code>)&#46; So while we introduced one additional step in the process to bootstrap a Rails application under JRuby, the removal the step where <code>database.yml</code> needs to be modified results in a more predictable workflow&#46;</p> <p>The new JRuby&#45;specific Rails workflow looks like the following, assuming you&#8217;ve installed the <code>activerecord-jdbc-adapter</code> gem into JRuby, along with the appropriate database driver gem (e&#46;g, <code>jdbc-mysql</code>)&#46; (Of course, the gems only need to be installed once per JRuby installation&#46;)</p> <ol> <li>Create your Rails application as usual&#46;</li> <li>Run the <code>jdbc</code> generator as shown above&#46;</li> <li>Profit!</li> </ol> <p>Additionally, if you maintain a <a href="http://m.onkey.org/2008/12/4/rails-templates">Rails application template</a> that you use to start a new application, you can simply add <code>generate(:jdbc)</code> to that template&#8217;s script&#46;</p> <p>What&#8217;s more, the presence of the JDBC files in your application are guarded and only inject JDBC support when running under JRuby, so you can safely keep them around when running Rails under multiple Ruby implementations&#46;</p> <p>For more details of what&#8217;s in the release please consult the <a href="http://rubyforge.org/forum/forum.php?forum_id=34972">mini&#45;changelog on Rubyforge</a> and the <a href="http://kenai.com/jira/browse/ACTIVERECORD_JDBC/fixforversion/10195">list of fixed issues in JIRA</a>&#46;</p> Mon, 12 Oct 2009 18:30:45 +0000 urn:uuid:65e528d4-1673-400f-b67c-60f97a152db4 Nick Sieger http://blog.nicksieger.com/articles/2009/10/12/fresh-0-9-2-activerecord-jdbc-adapter-release jruby activerecord jdbc http://blog.nicksieger.com/articles/trackback/528 ActiveRecord JDBC 0.5 <p>This one&#8217;s a bit late &#45;&#45; consider it part of my <a href="/articles/2007/07/13/pause">get&#45;caught&#45;up&#45;since&#45;unclogging&#45;the&#45;clogged&#45;blog</a> series&#46;</p> <p>ActiveRecord JDBC 0&#46;5 is out, so you may have heard (it went out the door a week ago Friday; c&#46;f&#46; <a href="http://blogs.sun.com/arungupta/entry/activerecord_jdbc_0_5_simplified">Arun</a> and <a href="http://www.bloglines.com/blog/ThomasEEnebo?id=36">Tom</a>)&#46; The major feature you get in this version is a new <code>database.yml</code> configuration style:</p> <div class="typocode"><pre><code class="typocode_default ">development: adapter: mysql database: blog_development username: root password:</code></pre></div> <p>Ok, ok, so what&#8217;s the big deal? This is just Rails&#8217; default database configuration&#46; Well, that&#8217;s the point &#45;&#45; you no longer have to know anything about JDBC URLs, driver class names, and all that&#46; We&#8217;ve baked it in for you&#46; This should make it easier than ever to try out your Rails application on JRuby, as the only piece of manual configuration left for you is the ugly bit of JRuby&#45;specific code you need to <a href="http://www.headius.com/jrubywiki/index.php/Running_Rails_with_ActiveRecord-JDBC">activate ActiveRecord&#45;JDBC</a> lurking right above the <code>Rails::Initializer</code>:</p> <div class="typocode"><pre><code class="typocode_ruby "><span class="keyword">if</span> <span class="constant">RUBY_PLATFORM</span> <span class="punct">=~</span> <span class="punct">/</span><span class="regex">java</span><span class="punct">/</span> <span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span> <span class="ident">gem</span> <span class="punct">'</span><span class="string">ActiveRecord-JDBC</span><span class="punct">'</span> <span class="ident">require</span> <span class="punct">'</span><span class="string">jdbc_adapter</span><span class="punct">'</span> <span class="keyword">end</span></code></pre></div> <p>If we can obliterate the need for this last bit of code, and make it easy to obtain the necessary driver bits, I&#8217;ll feel good enough to call this thing a 1&#46;0 product&#46;</p> Sun, 02 Sep 2007 04:47:26 +0000 urn:uuid:ed536239-db15-4a7d-963b-469c4b020d8f Nick Sieger http://blog.nicksieger.com/articles/2007/09/02/activerecord-jdbc-0-5 jruby activerecord http://blog.nicksieger.com/articles/trackback/272