Archive for the ‘Java’ Category

Standalone Migrations: Using Rails migrations in non Rails projects

Monday, December 22nd, 2008

Update 12/26/2008: I switched standalone migrations to use a Rakefile instead of a Ruby script.

Standalone MigrationsIn my work managing websites I end up working in Ruby, Java, and PHP. In everything but Rails managing the schema requires rolling your own solution. As a result I’ve started using Rails migrations in non-Rails projects to manage the schema. It’s not much code but I figured others might benefit from it so I created a little Github project called standalone migrations.

It’s based on Lincoln Stoll’s blog post titled Stand-alone ActiveRecord migrations and David Welton’s blog post titled Using Migrations Outside of Rails.

Assuming you have Ruby and Gem installed on your machine, here’s how to use it:

gem install -y activerecord rake mysql
wget http://github.com/thuss/standalone-migrations/zipball/master (or fetch it using git)
unzip it, and mv to something like my_non_rails_project/db
cd my_non_rails_project/db/ (or wherever you put it)
cp config/database_sample.yml config/database.yml
vi config/database.yml
./new_migration some_user_story
vi migrations/*_some_user_story.rb
rake db:migrate (this applies your newly created migration)

Moving to 64 bit Ubuntu

Friday, November 14th, 2008

Ubuntu LogoAfter 3 Ubuntu upgrades on my primary workhorse (a Lenovo Thinkpad z61t) I decided it was time for a fresh install to remove all the cruft. In the past I’ve always used 32 bit Ubuntu (even though my laptop is a 64 bit Core 2 duo) because of issues with the Flash plugin, Java plugin, and Skype. After backing up my files I bit the bullet and did a fresh install of 64 bit Ubuntu Intrepid Ibex and in the process also decided to give XFS a shot instead of EXT3 as my primary filesystem.

I’m pleased to say that after 3 hours I had the install done and all of my software installed and working including Jetbrains IDEA, Netbeans, Skype, VirtualBox, Flash plugin, Java plugin, Web Developer Toolbar, and Firebug. Apparently things have gotten a little better for 64 bit Linux over the past year and a half! However, I’m still running into odd issues every now and again related to both Sun’s 64 bit Java (IDE and Jetty occasionally hangs) and the the Open JDK browser plugin which is still buggy. Hopefully future updates will help address these issues. Anyhow, I thought I’d throw out the links I used to get everything working:

Fonts
Howto: Install Mac Fonts on Ubuntu
Make Firefox in Ubuntu look much better

Skype
Add the Medibuntu repository
sudo apt-get install skype-static

Flash plugin
Install Flash 10 Under Ubuntu Linux 64 bit Edition

Java plugin
sudo apt-get install openjdk-6-jre icedtea-gcjwebplugin

An interview with the authors of JRuby

Monday, January 22nd, 2007

The Java Posse hosted a great podcast interview with the authors of JRuby: Charles Nutter and Thomas Enebo. Additionally you get to hear what Tor Norbye is up to with his work on NetBeans Ruby integration and it looks like there’s some nice code assist features in the works! Really good code assist is the thing I miss most when doing Ruby (in RadRails) as opposed to Java (in IDEA).

It’s exciting to see the convergence of my two favorite languages coming along!

Tab completion and history with irb and script/console

Wednesday, December 6th, 2006

One thing I love about Ruby (and really miss when working in Java) is its interactive command line interpreter irb (or script/console if you’re using Rails). I really wish irb had tab completion and saved history configured by default out of the box. The good news is it’s easy to configure by creating a $HOME/.irbrc file with the following contents:
(more…)

Instantiating and populating a list or collection

Monday, November 20th, 2006

In Java it always irks me when I have to create a collection and then populate it in separate steps as follows:

List states = new ArrayList();
state.add(State.CA);
state.add(State.WY);

Then today I read about using an anonymous subclass with instance initializer to initialize a collection which appeals to the block loving Rubyist in me:
(more…)

Upgrading to Spring 2.0 and Hibernate 3.2

Thursday, October 19th, 2006

Tonight I just completed the upgrade from Spring 1.2 and Hibernate 3.1 to Spring 2.0 and Hibernate 3.2 for work. I was expecting a rough upgrade but was pleasantly surprised how easily it went.
(more…)

Xalan XSL transformations in the 1.4 JDK can be VERY slow

Friday, October 13th, 2006

At work as part of our XML data feed product we end up doing XSLT transformations on XML files starting a a few MB all the way up to several hundred MB. Using the 1.4.2 JDK it took over 4 days to do the XSL transformation on the largest file so over lunch one day we started brainstorming our troubleshooting approach. When we tried it on the 1.5 JDK the same transformation took a couple of minutes as opposed to 4 days. Talk about an improvement!
(more…)

Creating database test fixtures and the rails export fixtures plugin

Tuesday, May 16th, 2006

Being able to quickly and easily create test fixtures for your database is important yet it’s not always easy. There are basically 3 approaches I’ve seen used:

1. Use a MySQL or PostgreSQL dump that gets imported before the tests are run. I’ve never seen this approach used with Oracle, most likely because it’s such a PITA to export to text (or at least it used to be)
2. Just create the schema before the tests and then populate the test data in code
3. Use a database test fixture tool such as the XML based DBUnit for Java or Ruby’s YAML based fixtures
(more…)

Using log4j to monitor web application errors

Saturday, April 22nd, 2006

When monitoring a production website (especially with a dozen or so application servers) you don’t want to rely on combining the logs and reviewing them manually for exceptions, you want the servers to notify you when there’s a problem. There are really 3 pieces to doing this properly and they are:
(more…)

Why nobody is web testing in Java

Friday, April 14th, 2006

Go into any IDE and create a default Web project and you’ll often get JUnit, but I have yet to see one include some form of web testing support (e.g. Cactus, Cargo, and HttpUnit) and that’s just lame! (more…)